﻿#pragma once

#include <qobject.h>
#include <qvector.h>

#include "MEMSDataHandler.h"
#include "ScriptRunner.h"
#include "StateChecker.h"
#include "TurnTableCodec.h"
#include "TurnTableRunningStateManager.h"
#include "TurnTableConnectionStateManager.h"

/*
ScriptInstruction类为脚本指令的具体实现类提供接口和某些公共成员变量的管理。
所有脚本指令都应该继承该类。
*/
class ScriptInstruction :public QObject
{
  Q_OBJECT
public:
  //枚举类Instruction为全部指令类别提供编号，如果
  enum ScriptInstructionFlag {
    MetaInstruction_Wait = 1,//操作：等待
    //MetaInstruction_Goto,//操作：跳转
    //MetaInstruction_If,//操作：判断
    MetaInstruction_Loop,//操作开始一个循环
    Instruction_DataReader_StartCollection,//打开监听器
    Instruction_DataReader_StopCollection,//关闭监听器
    Instruction_TurnTable_Connect,//连接
    Instruction_TurnTable_Disconnect,//断开连接
    Instruction_TurnTable_SetLoad,//设置负载
    Instruction_TurnTable_PowerOn,//上电
    Instruction_TurnTable_PowerOff,//下电
    Instruction_TurnTable_CloseCircuit,//闭合
    Instruction_TurnTable_OpenCircuit,//闲置
    Instruction_TurnTable_Stop,//停止
    Instruction_TurnTable_EmergencyStop,//急停
    Instruction_TurnTable_SearchZero,//寻零
    Instruction_TurnTable_Zeroing,//回零
    Instruction_TurnTable_PositionMode,//位置方式参数
    Instruction_TurnTable_RateMode,//速率方式参数
    Instruction_TurnTable_Run,//运行
    Instruction_TurnTable_CurrentState,//查询现场数据
    Instruction_TurnTable_SearchZeroState,//查询寻零状态
    Instruction_TurnTable_RunningState,//查询运行状态
    Instruction_TurnTable_RunningMode,//查询运动方式
    Instruction_Thermostat_Connect,//打开温箱连接
    Instruction_Thermostat_Disconnect,//断开温箱连接
    Instruction_Thermostat_TargetTemperature,//设置温箱目标温度
    Instruction_Thermostat_CurrentTemperature,//查询温箱当前温度
    Instruction_Thermostat_TemperatureRate,//设置变温速率
    Instruction_TurnTable_QuitConsole//退出转台控制台
  };
private:
protected:
  ScriptInstructionFlag instructionFlag;
private:
  static MEMSDataHandler* mEMSDataHandler;
  static ScriptRunner* scriptRunner;
  static TurnTableCodec* turnTableCodec;
  static TurnTableRunningStateManager* turnTableRunningStateManager;
  static TurnTableConnectionStateManager* turnTableConnectionStateManager;
protected:
  ScriptInstruction(QObject* parent = Q_NULLPTR)
  {}
  ~ScriptInstruction()
  {}
public:
  virtual void run()=0;

public:
  ScriptInstructionFlag getInstructionFlag()
  {
    return instructionFlag;
  }
  virtual QVector<float> getDataForSaving()=0;

public:
  static MEMSDataHandler* getMEMSDataHandler()
  {
    return mEMSDataHandler;
  }
  static void setMEMSDataHandler(MEMSDataHandler* mEMSDataHandler)
  {
    ScriptInstruction::mEMSDataHandler = mEMSDataHandler;
  }
  static ScriptRunner* getScriptRunner()
  {
    return scriptRunner;
  }
  static void setScriptRunner(ScriptRunner* scriptRunner)
  {
    ScriptInstruction::scriptRunner = scriptRunner;
  }
  static TurnTableCodec* getTurnTableCodec()
  {
    return turnTableCodec;
  }
  static void setTurnTableCodec(TurnTableCodec* turnTableCodec)
  {
    ScriptInstruction::turnTableCodec = turnTableCodec;
  }
  static TurnTableRunningStateManager* getTurnTableRunningStateManager()
  {
    return turnTableRunningStateManager;
  }
  static void setTurnTableRunningStateManager(TurnTableRunningStateManager* turnTableRunningStateManager)
  {
    ScriptInstruction::turnTableRunningStateManager = turnTableRunningStateManager;
  }
  static TurnTableConnectionStateManager* getTurnTableConnectionStateManager()
  {
    return turnTableConnectionStateManager;
  }
  static void setTurnTableConnectionStateManager(TurnTableConnectionStateManager* turnTableConnectionStateManager)
  {
    ScriptInstruction::turnTableConnectionStateManager = turnTableConnectionStateManager;
  }
};
